/****************************************************
	文件：PlanRunner.cs
	作者：HuskyT
	邮箱：1005240602@qq.com
	日期：2020/8/26 17:47:1
	功能：计划执行器（框架层）
*****************************************************/

using System;
using System.Collections.Generic;
using UnityEngine;

namespace AIFramework.HTN
{
    public class PlanRunner
    {
        protected EntityBase mSelf;

        public PlanRunner(EntityBase entity)
        {
            mSelf = entity;
        }

        public void Run(Queue<PrimitiveTask> finalTasks)
        {
            mSelf.CurrentWorldState.LogWorldState("执行前");
            PrimitiveTask curTask = null;
            while (finalTasks.Count > 0)
            {
                curTask = finalTasks.Dequeue();
                Debug.LogFormat("执行 {0}", curTask.Name);
                curTask.Execute();
                curTask.ApplyEffects(mSelf.CurrentWorldState);
            }
            mSelf.CurrentWorldState.LogWorldState("执行后");
        }
    }
}
